<template>
  <div>
    <h2>当前求和为：{{ sum }}</h2>
    <select name="" id="" v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
    </select>
    <h1>{{ bigSum }}</h1>
    <button @click="add">加</button>
    <button @click="minus">减</button>
  </div>
</template>

<script setup lang='ts'>
import { ref, toRefs } from 'vue';
import { storeToRefs } from 'pinia'

import { useCountStore } from '../store/counts.ts'
// let countStore = ref(0)
const countStore = useCountStore()
// 只关注数据，不会涉及方法等的行为
const { sum, bigSum } = storeToRefs(countStore)
let n = ref(1)
// vuex中的数据不能直接改，而pinia可以直接改
function add() {
  //1、
  // countStore.sum += 1   
  // 2、$patch 碎片
  // countStore.$patch({
  // })
  countStore.increment(n.value)

}
function minus() {
  countStore.sum -= n.value
}
</script>

<style scoped lang='scss'></style>